// pages/mypage/coupon/coupon.js
const request = require('@/utils/request.js')
const constants = require('@/utils/khyConstants.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabIndex: 0,
    tabPanelstyle: '',
    ylqImg: getApp().globalData.nginxIp + "/img/ylqhongbao.png",
    qhbImg: getApp().globalData.nginxIp + "/img/wxzhongbao.png",
    yilingquImg: getApp().globalData.nginxIp + "/img/yilingqu.png",
    yishiyongImg: getApp().globalData.nginxIp + "/img/yishiyong.png",
    yiguoqiImg: getApp().globalData.nginxIp + "/img/yiguoqi.png",
    couponStatus: getApp().globalData.dictData['couponStatus'],
    myRedData: [],
    ksymyRedData: [],
    ysymyRedData: [],
    ygqmyRedData: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getPageData()
  },

  getPageData() {
    let user = getApp().getUserInfo()
    request.get('/UserController/getUserCoupon', {userNo: user.userNo}).then(res => {
      if (res.data.code == constants.resultSuccessCode
        && res.data.result) {
          let allData = res.data.result || []
          let ksyData = []
          let ysyData = []
          let ygqData = []
          for (let i = 0, n = allData.length; i < n; i++) {
            if (allData[i]['couponStatus'] == '1') {
              ksyData.push(allData[i])
            } else if (allData[i]['couponStatus'] == '2') {
              ysyData.push(allData[i])
            } else if (allData[i]['couponStatus'] == '3') {
              ygqData.push(allData[i])
            } 
          }

          this.setData({
            myRedData: allData,
            ksymyRedData: ksyData,
            ysymyRedData: ysyData,
            ygqmyRedData: ygqData
          })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})